package com.lyxs916.appbaselibrary.core.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.lyxs916.appbaselibrary.core.iview.BaseListViewListener;
import com.lyxs916.appbaselibrary.core.presenter.BasePresenter;
import com.lyxs916.xrecycleview.SuperRecyclerView;

import java.util.Collection;

/**
 * 说明:BaseListActivity 列表页面的父类，用于制件一些列表页面，不用重复实现一些方法
 * 作者： 杨阳; 创建于：  2017-06-14  11:02
 */
public abstract class BaseListActivity<V extends BaseListViewListener, P extends BasePresenter<V>> extends BaseMvpActivity<V, P>
        implements BaseListViewListener {

    protected SuperRecyclerView listSwipeView;

    @Override
    public void initView() {
        listSwipeView = getSuperRecyclerView();
        listSwipeView.setOnRefreshListener(this);
        listSwipeView.setOnLoaddingListener(this);
        listSwipeView.getRecyclerView().addItemDecoration(getItemDecoration());
        listSwipeView.getRecyclerView().setLayoutManager(getLayoutManager());
        listSwipeView.setAdapter(getAdapter());
        initView2();
    }

    /**
     * 重新实现initView
     */
    public abstract void initView2();

    /**
     * @return RecyclerView.ItemDecoration
     */
    public abstract RecyclerView.ItemDecoration getItemDecoration();

    /**
     * @return RecyclerView.Adapter
     */
    public abstract RecyclerView.Adapter getAdapter();


    public RecyclerView.LayoutManager getLayoutManager() {
        return new LinearLayoutManager(this);
    }

    @Override
    public <T> Collection<T> getValidData(Collection<T> c) {
        return listSwipeView.getPagingHelp().getValidData(c);
    }

    @Override
    public void clearPagingData() {
        listSwipeView.getPagingHelp().clear();
    }

    @Override
    public int getPageindex() {
        return listSwipeView.getPagingHelp().getPageindex();
    }

    @Override
    public int getPageCount() {
        return listSwipeView.getPagingHelp().getPageCount();
    }
}
